package com.business.img.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.business.img.entity.ImgData;
import com.business.img.service.ImgDataService;
import com.github.pagehelper.PageInfo;
import com.phiz.common.base.BaseController;
import com.phiz.common.base.Result;
import com.phiz.common.exception.HzBaseException;

@RestController
@RequestMapping("/img/data")
public class ImgDataController extends BaseController {

	@Autowired
	private ImgDataService imgDataService;

	@RequestMapping("/page")
	public Result page(Integer pageSize, Integer pageNum, ImgData img) {
		PageInfo<ImgData> page = imgDataService.findPage(pageSize, pageNum, img);
		return SUCCESS(page);
	}

	@RequestMapping("/save")
	public Result save(ImgData img) {
		try {
			imgDataService.insertSelective(img);
		} catch (HzBaseException e) {
			return ERROR(e);
		}
		return SUCCESS();
	}

	@RequestMapping("/edit")
	public Result edit(ImgData img) {
		try {
			imgDataService.updateByPrimaryKeySelective(img);
		} catch (HzBaseException e) {
			return ERROR(e);
		}
		return SUCCESS();
	}

	@RequestMapping("/del")
	public Result del(Long id) {
		try {
			imgDataService.deleteByPrimaryKey(id);
		} catch (Exception e) {
			return ERROR();
		}
		return SUCCESS();
	}

	@RequestMapping("/to/edit")
	public Result edit(Long id) {
		ImgData data = imgDataService.selectByPrimaryKey(id);
		return SUCCESS(data);
	}

}
